package com.jcark.utilscode.ext

import android.content.Context
import android.view.View
import androidx.annotation.*
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment

/**
 * Description:资源扩展函数 <br>
 * @author King.Zi<br>
 * @date 2022/11/23<br>
 * Email: 78688689@qq.com
 */
fun Context.getResourceColor(@ColorRes id: Int) = ContextCompat.getColor(this, id)

fun Context.getResourceDrawable(@DrawableRes id: Int) = ContextCompat.getDrawable(this, id)

fun Context.getResourceInteger(@IntegerRes id: Int) = resources.getInteger(id)

fun Context.getResourceBoolean(@BoolRes id: Int) = resources.getBoolean(id)

fun Context.getResourceString(@StringRes id: Int) = resources.getString(id)

fun Context.getResourceFormatString(@StringRes id: Int, vararg args: Any?) =
    String.format(resources.getString(id), *args)

fun Context.getResourceStringArray(@ArrayRes id: Int): Array<String> = resources.getStringArray(id)

fun Context.getResourceDimensionPixelSize(@DimenRes id: Int) = resources.getDimensionPixelSize(id)

fun View.getResourceColor(@ColorRes id: Int) = ContextCompat.getColor(this.context, id)

fun View.getResourceString(@StringRes id: Int) = context.getString(id)

fun View.getResourceFormatString(@StringRes id: Int, vararg args: Any?) = String.format(resources.getString(id), *args)

fun View.getResourceStringArray(@ArrayRes id: Int) = context.getResourceStringArray(id)

fun View.getResourceDrawable(@DrawableRes id: Int) = ContextCompat.getDrawable(this.context, id)

fun View.getResourceDimensionPixelSize(@DimenRes id: Int) = context.getResourceDimensionPixelSize(id)

fun Fragment.getResourceColor(@ColorRes id: Int) = ContextCompat.getColor(context!!, id)

fun Fragment.getResourceString(@StringRes id: Int) = context!!.getString(id)

fun Fragment.getResourceFormatString(@StringRes id: Int, vararg args: Any?) =
    String.format(resources.getString(id), *args)

fun Fragment.getResourceStringArray(@ArrayRes id: Int) = context!!.getResourceStringArray(id)

fun Fragment.getResourceDrawable(@DrawableRes id: Int) = ContextCompat.getDrawable(context!!, id)

fun Fragment.getResourceDimensionPixelSize(@DimenRes id: Int) = context!!.getResourceDimensionPixelSize(id)